<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="https://d3js.org/d3.v5.min.js"></script>
  <script src="./map.js"></script>
  <style>
#tooltip {
  position: absolute;
  z-index: 1;
  left: 0px;
  top:0px;
  padding: 20px;
  width: 200px;
  background: #666666;
  border-radius: 10px;
  display: none;

}

  </style>
</head>

<body>
  <div id="tooltip"></div>
  <div id="container">
  </div>
  <script>

    function createTooltip(d) {
      return `
          <h4>${d.properties.name}</h4>
          <table>
              <tr>
              <td>code:</td> <td>${d.properties.adcode}</td>
             </tr>
             <tr>
              <td>center:</td> <td>${d.properties.center}</td>
             </tr>
          </table>
  `
    }


    d3.json('./china.json').then((result) => {
      map('#container', result, function (d) {
        d3.select("#tooltip").html(
          createTooltip(d)
        )
        .style('display','block')
        .style('left',d3.event.pageX + 'px')
        .style('top',d3.event.pageY-10 + 'px')
      })
    })

  </script>

</body>

</html>